﻿using Photon.SocketServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common;
using Common.Tools;
using MyGameServer.Manager;
namespace MyGameServer.Handler
{
    
    public class LoginHandler : BaseHandler
    {
        public LoginHandler()
        {
            OpCode = OperationCode.Login;
        }

        public override void OnOPerationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer)
        {
            string username = DicTool.GetValue<byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username) as string;
            string passworld = DicTool.GetValue<byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password) as string;
            UserManager manager = new UserManager();
            bool isSuccess = manager.VerifyUser(username, passworld);
            OperationResponse response = new OperationResponse(operationRequest.OperationCode);
            //response.ReturnCode;成功或者失败
            if (isSuccess)
            {
                response.ReturnCode = (short)Common.ReturnCode.Success;
                peer.userName = username;
            }
            else
            {
                response.ReturnCode =(short) Common.ReturnCode.Failed;
            }
            peer.SendOperationResponse(response,sendParameters);
        }
    }
}
